<template>
  <div>
    <h1>班级列表</h1>
    <el-table :data="classesDate" border style="width: 100%">
      <el-table-column prop="_id" label="班级编号" width="180"> </el-table-column>
      <el-table-column prop="name" label="班级名称" width="180"> </el-table-column>
      <el-table-column prop="subjectsId.name" label="专业" width="180">
        <template slot-scope="scope">
          {{ scope.row.subjectsId ? scope.row.subjectsId.name : "暂无" }}
        </template>  
      </el-table-column>
      <el-table-column prop="directorsId.name" label="班主任" width="180">
        <template slot-scope="scope">
          {{ scope.row.classesId ? scope.row.classesId.name : "暂无" }}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >修改</el-button
          >
         <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageDate.currentPage"
      :page-sizes="[1, 5, 8, 10]"
      :page-size="pageDate.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions, mapState } =
  createNamespacedHelpers("classes");
  import pageMixins from '@/mixins/pageMixins.js'
export default {
  mixins:[pageMixins],
  created() {
    this.getClassesList();
  },
  methods: {
    ...mapActions(["getAllClass",'delClass']),
    
    getClassesList() {
      this.getAllClass(this.pageDate);
    },
    
    //修改
  //      handleEdit(index, row) {
  //        this.$router.push('/home/studentUpdate/'+row._id)
       
  //     },
  //          //删除
   async   handleDelete(index, row) {
        console.log(index, row);
          const data= await   this.delClass({_id:row._id})
          console.log(data);
          if(data.code){
               this.$message({
                message: '删除成功',
                type: 'success'
              });
              this.getClassesList()
          }else{
            alert(data.message)
          }

      }
  },
  computed: {
    ...mapState({
      classesDate: "rows",
      pages: "pages",
      total: "total",
    }),
  },
  watch: {
    pageDate: {
      handler() {
      
        this.getClassesList();
      },
      deep: true,
    },
  },

};
</script>

<style>
</style>